package com.railway.switchs.enums;

import java.util.HashMap;
import java.util.Map;

/**
 * @ClassName EnumNewsType枚举类
 * @Author 魏梓晟
 * @Version 1.0
 **/
public enum EnumNewsType {

    TO_BE_ANNOUNCED("0","待发布"),
    HAS_ANNOUNCED("1","发布中"),
    HAS_RESCINDED("2","已撤下");

    private String code;

    private String name;

    private EnumNewsType(String code, String name){
        this.code = code;
        this.name = name;
    }

    public String getCode() {
        return code;
    }

    public String getName() {
        return name;
    }

    private static Map<String, EnumNewsType> pool = new HashMap<>();

    static {
        for (EnumNewsType each : EnumNewsType.values()) {
            pool.put(each.getCode(), each);
        }
    }

    public static EnumNewsType get(String code) {
        return pool.get(code);
    }

    public static Map<String, String> getAllEnums() {
        Map<String, String> m = new HashMap<String, String>();
        for (EnumNewsType e : EnumNewsType.values()) {
            m.put(e.getCode(), e.getName());
        }
        return m;
    }

    public static String getName(String code){
        EnumNewsType enums = pool.get(code);
        if (enums == null) {
            return "";
        }
        return enums.getName();
    }
}
